<?php

require_once('lib/Schedule.php');
require_once('lib/Util.php');
require_once('lib/MixiAppliAPI.php');

$api = new MixiAppliAPI(array_merge($_GET, $_POST));

$api->validate_params(array(
    'schedule_id' => array('not_blank', 'is_numeric'),
    'start_date'  => array('date'),
    'start_time'  => array('time'),
    'end_date'    => array('date'),
    'end_time'    => array('time'),
    'flag'        => array(array('in_array',
        SCHEDULE_ALL,
        SCHEDULE_DAY,
        SCHEDULE_NIGHT,
    )),
));

$schedule = new Schedule($api->params['schedule_id']);
if ($api->viewer_id != $schedule->member_id)
    $api->set_error('has no auth');

$keys = array('start_date', 'start_time', 'end_date', 'end_time', 'flag');
foreach ($keys as $key) {
    if (isset($api->params[$key]))
        $schedule->$key = $api->params[$key];
}

if ($schedule->update() === FALSE)
    $api->set_error('could not update');

$api->set_result($schedule);

?>
